<?php 
class BaseTransactionReportForm extends BaseReportForm
{
    public function getModelName(){
        return "Transaction";
    }


    public function getOrderByFields(){
        return array(

        EmployeePeer::CODE  => 'employee code'
        , EmployeePeer::CARD_ID  => 'card id '
        , EmployeeI18nPeer::FIRST_NAME  => 'name'
        , EmployeePeer::HIRING_DATE  => 'hiring date'
        );
    }


    public $display_fields = array(
    'serial'=>'Serial'
    ,'employee_code'=>'Employee Code'
    ,'employee_name'=>'Employee name'
    ,'code_leave_type'=>'Leave type'
    ,'time_out'=>'Time Out'
    ,'time_in'=>'Time in'
    ,'period'=>'Period'
    );

    public function configure(){

    }


    protected function addCardIdColumnCriteria(Criteria $criteria, $field, $value=null){
        if($value !== null ){
            $criteria->addJoin( TransactionPeer::EMPLOYEE_ID ,EmployeePeer::ID );
            $criteria->add( EmployeePeer::CODE , $value );
        }

    }
    protected function addLeaveTypeIdColumnCriteria(Criteria $criteria, $field, $value=null){
        if($value !== null ){
            $criteria->add(TransactionPeer::LEAVE_TYPE_ID ,$value);
        }

    }


    protected function addOrderByColumnCriteria(Criteria $criteria, $field, $values){
        //$colname = $this->getColname($field);
        //die('asd');
        if(is_array($values) && count($values) > 0){
            $type = null;
            $field = null;
            foreach ($values as $k =>$v ){
                if($v=='Ascending' || $v=='Descending'){
                    $type = $v;
                }else{
                    $field = $v;

                }

            }//each

            $type = $type ? $type : 'Ascending';

            if($field){
                $criteria->addJoin(TransactionPeer::EMPLOYEE_ID  ,EmployeePeer::ID  );
                switch ($field) {
                    case EmployeeI18nPeer::FIRST_NAME :
                        $criteria->addJoin(EmployeePeer::ID , EmployeeI18nPeer::ID  );
                        $criteria->add(EmployeeI18nPeer::CULTURE ,sfContext::getInstance()->getUser()->getCulture() );
                        break;

                    default:
                        break;
                }
                call_user_func_array( array($criteria,sprintf('add%sOrderByColumn',ucfirst($type))) , array($field)  );

            }


        }

    }








}
